import { message } from 'antd';
import { routerRedux } from 'dva/router';
import { getLocalStorage } from '../../utils/cookieHelper';

export default {

  namespace: 'power',

  state: {
    postloading: false,
    actionpower: undefined,
    menupower: undefined,
  },

  subscriptions: {},

  effects: {
    * setpower({ payload }, { call, put }) {
      var thispower = getLocalStorage('power');
      var actionparams = [];
      thispower.map(function(item) {
        item.children.map(function(citem) {
          actionparams.push(citem);
        });
      });
      var action = actionparams.find(function(item) {
        return item.url == payload;
      });
      yield put({ type: 'setpowerstate', payload: action });
    },
    * setmenupower({ payload }, { call, put }) {
      var currPower = getLocalStorage('power');
      yield put({ type: 'setmenupowerstate', payload: currPower });
    },
  },

  reducers: {
    setmenupowerstate(state, { payload }) {
      return {...state, menupower: payload }
    },
    setpowerstate(state, { payload }) {
      return {...state, actionpower: payload }
    }
  },

};